package com.mtsmda.chapter4;

public class StringConcationationEx {

	public static void main(String[] args) {

		String s = "JAVA ";
		int c = 15;
		int g = 97;
		System.out.println(s + c + g);
		System.out.println(s + (c + g));
		System.out.println((s + c) + g);

		int x = 2, y = 3;
		if ((y == x++) | (x < ++y)) {
			System.out.println("x = " + x + "; y = " + y);
		}

		System.out.println((5 < 9) ? (11 < 8) ? "11 > 8" : "False 11 > 8"
				: "False");

		bitwiseOperators();
		System.out.println("____________");
		experimentsShortCircuitLogicalOperators();
		System.out.println("____________");
		experimentsNonShortCircuitLogicalOperators();

		/*if(6 && 5){
			System.out.println(); // fool in exam(error!)
		}*/
	}

	static void bitwiseOperators() {
		int g = 15;
		int c = 19;
		int p = 10;

		System.out.println((g | c));
		/*
		 * 15 or 19 = 31 01111 10011 11111
		 */
		System.out.println((g & p));
		/*
		 * 15 and 10 = 10 1111 1010 1010
		 */
		System.out.println((g ^ c));
		/*
		 * 15 or not 19 = 28 01111 10011 11100
		 */

	}

	static void experimentsShortCircuitLogicalOperators() {
		if (isSmall(7) || isSmall(2)) {
			System.out.println("first true");
		}
		if (isSmall(3) || isSmall(9)) {
			System.out.println("second true");
		}
	}

	static boolean isSmall(int c) {
		if (c < 5) {
			System.out.println(c + " < 5");
			return true;
		} else {
			System.out.println(c + " >= 5");
			return false;
		}
	}
	
	static void experimentsNonShortCircuitLogicalOperators(){
		int x = 5;
		if(++x > 5 || ++x >6){
			System.out.println(x);
		}
		
		x = 5;
		if(++x > 5 | ++x > 6){
			System.out.println(x);
		}
	}
}